////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                                                            //
//                                                         WNProject                                                          //
//                                                                                                                            //
//            This file is distributed under the BSD 2-Clause open source license. See License.txt for details.               //
//                                                                                                                            //
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#pragma once

#ifndef __WN_SCRIPTING_SCRIPT_LEXER_DEFINES_H__
#define __WN_SCRIPTING_SCRIPT_LEXER_DEFINES_H__

#include "WNScripting/inc/WNIdentifierMap.h"
#include "WNScripting/inc/WNTypeManager.h"
#include "WNScripting/inc/WNScriptDefinedElement.h"
#include "WNCore/inc/WNPlatform.h"
#include "WNStrings/inc/WNStrings.h"

namespace WNScripting {
    #define WN_SCRIPT_WHITESPACE     1
    #define WN_SCRIPT_EOF           -1
    #define WN_SCRIPT_ERR           -2
    #define WN_SCRIPT_IGNORE         2

    class WNParseTree;

    struct WNLexerInfo {
        WNIdentifierElement mFilename;
        WN_CHAR* mStart;
        WN_CHAR* mEnd;
        WN_CHAR* mMarker;
        WN_CHAR* mFileStart;
        WN_SIZE_T mCharNo;
        WN_SIZE_T mLineNo;
        WNIdentifierMap* mIdentifierMap;
        WNTypeManager* mTypeManager;
    };

    WN_VOID WNLexerInitialize(WNLexerInfo* _lex);
    WN_VOID WNLexerReportError(WNLexerInfo* _lexer, const WN_CHAR* _message, const WN_CHAR* _lexed, WN_SIZE_T _lineno, WN_SIZE_T _charno);

    struct WNScriptToken {
        WN_SIZE_T mStartLine;
        WN_SIZE_T mEndLine;
        WN_SIZE_T mStartChar;
        WN_SIZE_T mEndChar;
        WN_UINT32 mId;
        WNIdentifierElement mTokenString;

        union {
            WNS_INT_CONST mIntConst;
            WNS_FLOAT_CONST mFloatConst;
            WNS_CHAR_CONST mCharConst;
            WNS_STRING_CONST mStringConst;
        };
    };
}
WN_VOID  WNScriptParse     (WN_VOID *_parser, int _tokencode, WNScripting::WNScriptToken* _token, WNScripting::WNParseTree** _tree);
WN_VOID* WNScriptParseAlloc(WN_VOID *(*)(size_t));
WN_VOID  WNScriptParseFree (WN_VOID *_p, WN_VOID (*_freeProc)(WN_VOID*));
WN_INT32 WNScriptLex(WNScripting::WNLexerInfo* _s, WNScripting::WNScriptToken* _token);
    WN_INT32 WNQuickLex(WNScripting::WNLexerInfo* _s, WNString& _errormsg, std::list<WNScripting::WNScriptDefinedElement*>& _scriptAccessibleItems, WNScripting::WNScriptingEngineData& _data);
#ifdef _WN_DEBUG
    WN_VOID WNScriptParseTrace(FILE *TraceFILE, char *zTracePrompt);
#endif
#endif // __WN_SCRIPTING_SCRIPT_LEXER_DEFINES_H__
